home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Add-Ons / MicroPhone / Open Mike™ / Open Mike™ 004 / Mike's Folder / Funky Functions II < prev    next >
Encoding:
Text File  |  1993-03-31  |  5.6 KB  |  78 lines  |  [TEXT/ttxt]

  1. Funky Functions II
  2. ==================
  3. by Norman Lee
  4. Copyright © 1993 by Celestin Company
  5. All rights reserved.
  6.  
  7. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without permission in writing from the publisher. However, you are permitted to make copies of this work, printed or otherwise, as long as said copies are for your personal use only.
  8.  
  9. Introduction
  10. ------------
  11. You probably didn't think you'd hear from me again so soon. Just as I finished my first article for Open Mike, I came up with a few new pseudo-functions for MicroPhone, based on a particular need I had. For those of you who are joining us for the first time, welcome! And here is a brief synopsis of what we did last time (actually it's a huge segment from the previous article, but I can do whatever I want, right?):
  12.  
  13. MicroPhone does not really support the ability to include functions of your own making, unless you are adept at creating XFCNs in a programming language such as Pascal. However, there is a method of faking functions. For the sake of clarity, we'll call our scripted functions "pseudo-functions". For example, if you've created a pseudo-function called "starDate", which returns the current date in the form used by a popular television program, to get this date, run the script called "starDate". The properly formatted date will be returned to you in a variable with the same name as the script. So, for example, you might do the following:
  14.  
  15.   Do Script "'starDate'"
  16.   Alert OK "'Captain''s Log, Star Date ' & starDate & '.'"
  17.  
  18. What sets starDate apart from being a true function is the fact that MicroPhone scripts cannot return values. If they did, you'd be able to do the following:
  19.  
  20.   Set Variable myDate from Expression "starDate"
  21.  
  22. MicroPhone should then look for a script by the same name. If one is found, and the script sets the variable starDate, then starDate should be returned. If no script is found, then MicroPhone should look for the XFCN starDate. If none is found, then look for a true function. If none, then the variable starDate. If no go here, then nothing will be returned. Useful addition to MicroPhone? I think so.
  23.  
  24. OK, that's the end of the stuff from the previous article. Now, onto the new stuff. I'm including five more pseudo-functions I needed to write when a client of mine wanted me to do stress testing of a new system. You can find these new pseudo-functions in a module called "Extras2", which should be kept in your Module Folder. This way, any settings document that wants to, can share the pseudo-functions.
  25.  
  26. Here's what's in Extras2:
  27.  
  28. uniqueFileName
  29. fileCount
  30. itemPosition
  31. random
  32.  
  33. These pseudo-functions are described in detail below. In order the make them available to your settings document, include the following script line in your setting document's startup script:
  34.  
  35.   Module Load "'Extras2'"
  36.  
  37. Then, whenever you want to use a particular pseudo-function, use the following syntax:
  38.  
  39.   Do Script "'uniqueFileName'"
  40.   Alert OK "uniqueFileName"
  41.  
  42. uniqueFileName
  43. --------------
  44. When you need to generate a filename based on another file that already exists, or if you want to make sure that you don't overwrite a file of the same name, use this pseudo-function. It will take the full path and name you give it and return a valid file name. If the file whose name you give it does not exist, it will simply strip the path and return the name you gave it. However, if the file does exist, it uses the following logic to create a new name:
  45.  
  46. Append a '1' to the end of the name. If this name exists, increment the number until a unique name is generated. If the new name is greater than 31 characters, truncate characters from the end of the name (not including appended numbers) until the name is 31 characters long. Example:
  47.  
  48.   Set Variable uniqueFileName from Expression "'Hard Disk:icky poo'"
  49.   Do Script "'uniqueFileName'"
  50.   Alert OK "'Unique name will be ' & uniqueFileName & '.'"
  51.  
  52. fileCount
  53. ---------
  54. In order to determine how many files of a certain type exist in a directory, use this pseudo-function. Pass to it the full path of the directory, a carriage return, and the type of file you are looking for (leave it blank if you want it to return a count of all files). For example, if you want to see how many text files are in directory 'Hard Disk:Utilities:', do this:
  55.  
  56.   Set Variable fileCount from Expression "'Hard Disk:Utilities:^MTEXT'"
  57.   Do Script "'fileCount'"
  58.   Alert OK "'There are ' & String(fileCount) & ' text files here.'"
  59.  
  60. itemPosition
  61. ------------
  62. This pseudo-function returns you the position of the desired item in a delimited list. For example, if you are looking for the position of banana in the list apple,banana,cherry, itemPosition will return 2. You need to pass the list, the delimiter, and the item you whose position you are looking for. Use the | character to delimit these three parameters. Example:
  63.  
  64.   Set Variable itemPosition from Expression "'apple,banana,cherry|,|banana'"
  65.   Do Script "'itemPosition'"
  66.   Alert OK "'Banana is in position ' & String(itemPosition) & '.'"
  67.  
  68. random
  69. ------
  70. This pseudo-function returns to you either zero or one, randomly. Don't ask me what you would ever use it for. Maybe a decision maker or coin toss situation. Example:
  71.  
  72.   Do Script "'random'"
  73.   Alert OK "'I randomly chose ' & String(random) & '.'"
  74.  
  75. Final Thoughts
  76. --------------
  77. Write to me if you use any of these functions or have ideas for new ones. I'd love to hear from you. You can write to any of the electronic address that appear elsewhere in Open Mike. Just make sure my name is on it somewhere and it will get to me.
  78.